home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
DICACHE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-09-11
|
4KB
|
113 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: dicache.c
// Title: Data File I/O Library
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This module contains routines to assist in caching of blocked files.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <di.h>
//----------------------------------------------------------------------------
// Description: Release cache for file
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioCacheRelease(HLF hlf)
{
Assert(hlf >= 0 && hlf < MAX_LOGICAL_FILES);
Assert(di.logical[hlf].fUsed);
if (di.logical[hlf].pcache) // Free cache if allocated
MemFree(di.logical[hlf].pcache);
di.logical[hlf].pcache = NULL; // Reset cache vars
di.logical[hlf].cCache = 0;
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Set caching buffers for blocked files.
// Caching only applies to blocked files.
// No error is displayed if allocation of caching buffers
// fails,
// Buffers are released if low memory flag is set.
// Parameters: hlf Logical file to cache.
// cBuffers Number of cache buffers to allocate
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioCacheSet(HLF hlf, SIZET cBuffers)
{
SIZET cb, cbBlock,cbMax;
Assert(hlf >= 0 && hlf < MAX_LOGICAL_FILES);
Assert(di.logical[hlf].fUsed);
if (!DioCacheRelease(hlf)) // Release existing cache
return FALSE;
//
// File can not be cached if not blocked or if writeable.
// Do not cache if low on memory
//
if (MemIsLowMemory()
|| !cBuffers
|| !di.logical[hlf].usBlockSize)
return FALSE;
// Calculate sizes and limits
cbBlock = (SIZET)di.logical[hlf].usBlockSize;
cbBlock += sizeof(CACHE) - sizeof(BYTE);
cbMax = 32767 / cbBlock; //rather then using 32 _K which will give a
// value of 32768 (1 too many), set it to 32767
if (cBuffers > cbMax)
cBuffers = cbMax;
cb = cbBlock * cBuffers;
// Allocate cache
di.logical[hlf].pcache = MemAllocZero(cb);
if (di.logical[hlf].pcache == NULL)
return FALSE;
di.logical[hlf].cCache = cBuffers;
return TRUE;
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------